<template>
  <div>
    <el-form
        :model="MesBaseParams"
        class="mes-base-params-form-inline"
        size="small"
        label-width="130px"
        label-position="left"
        :inline="true"
    >
      <div style="display: flex">
        <div style="font-weight: 700;  color: #606266; padding: 10px 0;font-size: 12px;color:red">
          标注:MESCFG.ini 配置项标签：(仅支持下划线和英文)
        </div>
        <!--        <label style="color: red;user-select: text">{{ ApiName }}</label>-->
      </div>
      <el-form-item class="mbpfi-item" label="MES配置标签项" label-width="100px" style="width: 92%">
        <el-input v-model="ApiName" placeholder="URL" style="color:red" @change="SearchMesConfigBtn">
          <template #prepend>{{ currentClickNodeMixin.id }}</template>
          <template #append>
            <el-button @click="SearchMesConfigBtn">手动检索</el-button>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item class="mbpfi-item" label="URL" label-width="100px" style="width: 92%">
        <el-input
            v-model="MesBaseParams.Url"
            type="textarea"
            :rows="2"
            placeholder="URL"
            style="width: 99%"
        ></el-input>
      </el-form-item>
      <el-form-item label="Timeout">
        <el-input
            v-model="MesBaseParams.Timeout"
            type="Number"
            placeholder="请求超时时间"
            style="width: 100%"
            min="3000"
        ></el-input>
      </el-form-item>
      <el-form-item label="UserName">
        <el-input v-model="MesBaseParams.UserName" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item label="Password">
        <el-input v-model="MesBaseParams.Password" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item label="User">
        <el-input v-model="MesBaseParams.User" placeholder="操作用户"></el-input>
      </el-form-item>
      <el-form-item label="Site">
        <el-input v-model="MesBaseParams.Site" type="Number" placeholder="基地站点"></el-input>
      </el-form-item>
      <el-form-item label="ActivityId">
        <el-input v-model="MesBaseParams.ActivityId" placeholder="ActivityId"></el-input>
      </el-form-item>
      <!--      <el-form-item label="remark">-->
      <!--        <el-input v-model="MesBaseParams.remark" placeholder="描述"></el-input>-->
      <!--      </el-form-item>-->
      <el-form-item label="Operation">
        <el-input v-model="MesBaseParams.Operation" placeholder="Operation"></el-input>
      </el-form-item>
      <el-form-item label="OperationRevision">
        <el-input v-model="MesBaseParams.OperationRevision" placeholder="OperationRevision"></el-input>
      </el-form-item>
      <el-form-item label="Resource">
        <el-input v-model="MesBaseParams.Resource" placeholder="资源号"></el-input>
      </el-form-item>
      <el-form-item label="DcGroup">
        <el-input v-model="MesBaseParams.DcGroup" placeholder="数据数据组"></el-input>
      </el-form-item>
      <el-form-item label="DcGroupRevision">
        <el-input v-model="MesBaseParams.DcGroupRevision" placeholder="DcGroupRevision"></el-input>
      </el-form-item>
      <el-form-item label="ModeProcessSFC">
        <el-input v-model="MesBaseParams.ModeProcessSFC" placeholder="过站模式"></el-input>
      </el-form-item>
      <el-form-item label="dcMode">
        <el-input v-model="MesBaseParams.dcMode" placeholder="dcMode"></el-input>
      </el-form-item>
      <el-form-item label="dcGroupSequence">
        <el-input v-model="MesBaseParams.dcGroupSequence" placeholder="dcGroupSequence"></el-input>
      </el-form-item>
      <el-form-item label="material">
        <el-input v-model="MesBaseParams.material" placeholder="material"></el-input>
      </el-form-item>
      <el-form-item label="materialRevision">
        <el-input v-model="MesBaseParams.materialRevision" placeholder="materialRevision"></el-input>
      </el-form-item>
      <el-form-item label="sfcQty">
        <el-input v-model="MesBaseParams.sfcQty" placeholder="sfcQty"></el-input>
      </el-form-item>
      <el-form-item style="margin-bottom: 0;width: 90%" class="flex-jc-end">
        <el-button type="primary" round @click="saveNodeMesParams">保存参数</el-button>
        <el-button type="text" round @click="openConfigFile">打开配置文件</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { GetMesNodeRequestParams, SaveMesRequestParams } from '@/api/flow/flow'
import Utils from '../../../../utils/Common'
import NodeConfigMixin from '../../../../libs/NodeConfigMixin.js'
import SystemApi from '@/api/flow/SystemApi'
import { MessageSuccess } from "@/utils";
import { FlowApi } from "@/api/FlowApi";
import { System } from "@/api/SystemApi";

export default {
  name: 'BaseParamsForm',
  mixins: [NodeConfigMixin],
  props: {
    node: {
      type: Object,
      deep: true,
      immediate: true
    }
  },
  data () {
    return {
      MesBaseParams: {
        Url: null,
        Timeout: 3000,
        UserName: null,
        Password: null,
        User: null,
        Site: null,
        ActivityId: null,
        remark: null,
        Operation: null,
        OperationRevision: null,
        Resource: null,
        DcGroup: null,
        DcGroupRevision: null,
        ModeProcessSFC: null,
        dcMode: null,
        dcGroupSequence: null,
        material: null,
        materialRevision: null,
        sfcQty: null
      },
      ApiName: null
    }
  },
  methods: {
    /**
     * 检索MES配置
     * @constructor
     */
    SearchMesConfigBtn () {
      this.FindMesParams();
    },
    saveNodeMesParams () {
      const Params = this.MesBaseParams
      const Section = this.currentClickNodeMixin.id + '_' + this.ApiName
      SaveMesRequestParams(Section, Params, (res) => {
        MessageSuccess('修改成功')
      })
    },
    openConfigFile () {
      System.OpenFile({ Path: null, FileName: 'MESCFG.ini' })
    },
    /**
     * 查询MES配置
     * @constructor
     */
    FindMesParams () {
      const Section = this.currentClickNodeMixin.id + '_' + this.ApiName
      FlowApi.GetMesNodeRequestParams(Section).then(res => {

        function SetDefault () {
          if (Utils.IsEmpty(res.Data.OperationRevision)) {
            res.Data.OperationRevision = '#'
          }
          if (Utils.IsEmpty(res.Data.DcGroupRevision)) {
            res.Data.DcGroupRevision = '#'
          }
          if (Utils.IsEmpty(res.Data.materialRevision)) {
            res.Data.materialRevision = '#'
          }
          if (Utils.IsEmpty(res.Timeout) || res.Data.Timeout <= 0) {
            res.Data.Timeout = 30000
          }
        }

        SetDefault()
        this.MesBaseParams = res.Data
      })
    }
  },
  created () {
    this.ApiName = this.currentClickNodeMixin.nodeType
    this.FindMesParams()
  }
}
</script>

<style lang="less">
.mes-base-params-form-inline {
  height: calc(100vh - 200px);
  overflow-y: auto;

  .el-form-item {
    margin-right: 6px;
  }

  .mbpfi-item {
    > div {
      width: 85%;
    }
  }
}
</style>
